#include "tetris.h"

tetris::tetris()
{
    //初始化随机数发生器
    srand(unsigned(time(NULL)));

    //初始化成员变量
    score = 0;
    for (int i = 0; i < MAXX; i++)
    {
        for (int j = 0; j < MAXY; j++)
        {
            box[i][j] = 0;
        }
    }
    for (int i = 0; i < COUNT; i++)
    {
        block.x[i] = -1;
        block.y[i] = -1;
    }
    block.centerX = -1;
    block.centerY = -1;
    block.ID = 0;
    //创建下一个方块
    createNextBlock();
}

//创建当前方块
//将上一次生成的下一个方块nextBlock复制给block
//并创建下一个nextBlock
void Tetris::createBlock()
{
    //nextBlock复制给block
    for (int i = 0; i < COUNT; i++)
    {
        block.x[i] = nextBlock.x[i];
        block.y[i] = nextBlock.y[i];
    }
    block.centerX = nextBlock.centerX;
    block.centerY = nextBlock.centerY;
    block.ID = nextBlock.ID;

    //创建下一个nextblock
    createNextBlock();
}


//返回下一个方块
Block Tetris::getNextBlock()
{
    return nextBlock;
}


//返回当前方块
Block Tetris::getBlock()
{
    return block;
}


//返回当前分数
int Tetris::getScore()
{
    return score;
}


//返回坐标（x，y）的值，以判断是否右方格
int Tetris::getBox(int x, int y)
{
    return box[x][y];
}

//获得游戏窗口的宽度
int Tetris::getWidth()
{
    return MAXX * WIDTH + (MAXX - 1) * INTERVAL;
}


//获得游戏窗口的高度
int Tetris::getHeight()
{
    return MAXY * HEIGHT + (MAXY - 1) * INTERVAL;
}


//获得“下一个”窗口的宽度
int Tetris::getNextWidth()
{
    return NEXTMAXX * WIDTH + (NEXTMAXX - 1) * INTERVAL;
}


//获得“下一个”窗口的高度
int Tetris::getNextHeight()
{
    return NEXTMAXY * WIDTH + (NEXTMAXY - 1) * INTERVAL;
}
